<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jstl/core"
      xmlns:j="http://metalframework.org">
      
	<body>
		<ui:composition template="/WEB-INF/templates/template.xhtml">
			<ui:define name="content">
				<j:keep id="ownerId" value="#{param.ownerId}" />
				<j:keep id="petId" value="#{param.petId}" />
				<j:keep id="currentOwner" value="#{clinic.getOwnerById(ownerId)}" dependsOn="ownerId" />

				<c:choose>
					<c:when test="#{empty petId}">
						<j:keep id="currentPet" value="#{pet}" dependsOn="petId" />
					</c:when>
					<c:otherwise>
						<j:keep id="currentPet" value="#{currentOwner.getPetById(petId)}" dependsOn="petId" />
					</c:otherwise>
				</c:choose>
				
				<h2>
					<c:if test="#{empty petId}">
						<h:outputText value="New " />
					</c:if>
					Pet:
				</h2>
				
				<b>Owner: </b>
				<h:outputText value="#{currentOwner.firstName} #{currentOwner.lastName}" />

				<h:form>
					<h:panelGrid columns="1" styleClass="form">
						<h:column>
							<h:outputLabel value="Name:" for="name" />
							<h:message for="name" styleClass="errors" />
							<br />
							<h:inputText value="#{currentPet.name}" id="name" size="30" maxlength="30" />
						</h:column>
						<h:column>
							<h:outputLabel value="Birth Date:" for="birthDate" />
							<h:message for="birthDate" styleClass="errors" />
							<br />
							<h:inputText value="#{currentPet.birthDate}" id="birthDate" size="10" maxlength="10">
								<f:convertDateTime pattern="yyyy-MM-dd" timeZone="America/Sao_Paulo" />
							</h:inputText>
							<h:outputText value=" (yyyy-mm-dd)" />
						</h:column>
						<h:column>
							<h:outputLabel value="Type:" for="type" />
							<h:message for="type" styleClass="errors" />
							<br />
							<h:selectOneMenu value="#{currentPet.type}" id="type" converter="petClinicEnumConverter">
								<j:enumSelectItems class="org.metalframework.samples.petclinic.Pet$Type"
												   comparator="org.metalframework.jsf.tag.ToStringEnumComparator" />
							</h:selectOneMenu>
						</h:column>
						<h:column>
							<span class="submit">
								<c:choose>
									<c:when test="#{empty petId}">
										<h:commandButton action="#{currentOwner.adopt(currentPet)}"
														 value="Add Pet" />
									</c:when>
									<c:otherwise>
										<h:commandButton action="#{currentOwner.updatePet(currentPet)}"
														 value="Update Pet" />
									</c:otherwise>
								</c:choose>
							</span>
						</h:column>
					</h:panelGrid>
				</h:form>
			</ui:define>
		</ui:composition>
	</body>
</html>
